package com.tsinghuabigdata.edu.ddmath.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tsinghuabigdata.edu.ddmath.R;
import com.tsinghuabigdata.edu.ddmath.bean.SubmitQuestion;
import com.tsinghuabigdata.edu.ddmath.util.DateUtils;

import java.util.List;

import static com.tsinghuabigdata.edu.ddmath.module.ddwork.bean.LocalWorkInfo.WORK_COMMITFAIL;
import static com.tsinghuabigdata.edu.ddmath.module.ddwork.bean.LocalWorkInfo.WORK_COMMITING;

/**
 * 待提交机构作业——适配器
 * Created by Administrator on 2017/2/17.
 */

public class ToSubmitAgencyWorkAdatper extends CommonAdapter<SubmitQuestion> {

    String[] weeks = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"};

    public ToSubmitAgencyWorkAdatper(Context context, List<SubmitQuestion> mDatas) {
        super(context, mDatas);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_to_submit;
    }

    @Override
    protected void convert(ViewHolder helper, int position, SubmitQuestion item) {
        LinearLayout llPageCount= helper.getView(R.id.ll_page_count);
        TextView tvPageCount = helper.getView(R.id.tv_page_count);
        LinearLayout llSubmitting = helper.getView(R.id.ll_submitting);
        LinearLayout llSubmitFail= helper.getView(R.id.ll_submit_fail);
        if (item.getStatus() == WORK_COMMITING) { //提交中
            llSubmitting.setVisibility(View.VISIBLE);
            llSubmitFail.setVisibility(View.INVISIBLE);
            llPageCount.setVisibility(View.INVISIBLE);
        } else if (item.getStatus() == WORK_COMMITFAIL) { //提交失败
            llSubmitting.setVisibility(View.INVISIBLE);
            llSubmitFail.setVisibility(View.VISIBLE);
            llPageCount.setVisibility(View.INVISIBLE);
        } else {
            llSubmitting.setVisibility(View.INVISIBLE);
            llSubmitFail.setVisibility(View.INVISIBLE);
            llPageCount.setVisibility(View.VISIBLE);
            tvPageCount.setText(item.getTakedpageCount() + "/" + item.getPageCount());
        }

        ImageView ivOverdue = helper.getView(R.id.iv_overdue);
        String startTime = item.getStartTime();
        //        String day = startTime.substring(8, 10);
        String day = startTime.substring(5, 7) + "月" + startTime.substring(8, 10) + "日";
        if (startTime.equals(DateUtils.getToday())) {
            helper.setText(R.id.tv_day, "今日");
        } else {
            helper.setText(R.id.tv_day, day);
        }
        String week = weeks[item.getWeek()];
        helper.setText(R.id.tv_week, week);
        helper.setText(R.id.tv_title, item.getExerName());
        String endTime = item.getEndTime();
        String endDay = endTime.substring(5, 7) + "月" + startTime.substring(8, 10) + "日 12:00结束";
        helper.setText(R.id.tv_end_time, endDay);
        if (item.isOverdue()) {
            ivOverdue.setVisibility(View.VISIBLE);
        } else {
            ivOverdue.setVisibility(View.INVISIBLE);
        }

    }
}
